from gi.repository import Gio
import os
from PIL import Image

class IconManager:
    def __init__(self, settings):
            self.settings = settings

                def set_icon(self, folder_path, icon_path):
                        """设置文件夹图标并保存最后使用的路径"""
                                desktop_file = os.path.join(folder_path, ".directory")
                                        with open(desktop_file, "w") as f:
                                                    f.write(f"[Desktop Entry]\nIcon={icon_path}\n")
                                                            
                                                                    # 保存到GSettings
                                                                            self.settings.set_string("last-icon-path", icon_path)
                                                                                    self.settings.apply()

                                                                                        @staticmethod
                                                                                            def generate_thumbnail(source_path, size=(128, 128)):
                                                                                                    """生成缩略图"""
                                                                                                            img = Image.open(source_path)
                                                                                                                    img.thumbnail(size)
                                                                                                                            return img